#define _CRT_SECURE_NO_WARNINGS
#include"stack.h"
void STInit(ST* ps) {
	ps->a = NULL;
	ps->top = 0;
	ps->capacity = 0;
}

void STDestroy(ST* ps) {
	ps->a = NULL;
	ps->top = 0;
	ps->capacity = 0;
}

void STPush(ST* ps, int x) {
	if (ps->top == ps->capacity) {
		int newcapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;
		int* tmp = (int*)malloc(sizeof(int) * newcapacity);
		if (tmp == NULL) {
			perror("malloc failed");
			exit(-1);
		}
		ps->a = tmp;
		ps->capacity = newcapacity;
	}
	ps->a[ps->top] = x;
	ps->top++;
}

void STPop(ST* ps) {
	ps->top--;
}

int STTop(ST* ps) {
	return ps->a[ps->top - 1];
}

int STSize(ST* ps) {
	return ps->top;
}

bool STEmpty(ST* ps) {
	return ps->top == 0;
}